/*
 * @Description  : 登录接口
 * @Author       : YiDing Xue
 * @Date         : 2023-01-12
 * @LastEditors  : YiDing Xue
 * @LastEditTime : 2023-03-10
 */
import { request } from '@/utils'

const API = {
  passwordLogin: '/user/login', // 用户名/手机号 + 密码登录
  userInfo: '/user/userInfo', // 当前登陆者信息
  getSMSCode: '/user/phoneSendCode', // 获取短信验证码
  codeLogin: '/user/phoneLogin', // 验证码登录
  registered: '/user/registered', // 注册
  phoneBind: '/user/phoneBind', // 绑定手机号
  refreshToken: '/refreshToken', // 刷新 token
  selCollectionWorksList: '/collectionWorks/selCollectionWorksList', // 查询作品收藏列表
  addAddress: '/address/addAddress', // 新增收货地址
  updateAddress: '/address/updateAddress', // 修改用户地址
  deleteAddress: '/address/deleteAddress', // 删除用户地址
  selAddress: '/address/selAddress' // 查询用户地址
}

/**
 * 用户名/手机号 + 密码登录
 * @param {String} parameter 用户名/手机号
 * @param {String} password 密码
 * @returns
 */
export const passwordLogin = (parameter, password) =>
  request.post(API.passwordLogin, { parameter, password }, { noNeedToken: true })

/**
 * 获取当前用户信息
 * @returns
 */
export const userInfo = () => request.get(API.userInfo, { noNeedTip: true })

export const refreshToken = () => request.get(API.refreshToken)

/**
 * 获取短信验证码
 * @returns
 */
export const getSMSCode = phoneNumber => request.post(API.getSMSCode, { phoneNumber }, { noNeedToken: true })

/**
 * 获取短信验证码
 * @returns
 */
export const codeLogin = (phoneNumber, phoneCode) =>
  request.post(API.codeLogin, { phoneNumber, phoneCode }, { noNeedToken: true })

/**
 * 注册
 * @returns
 */
export const registered = (username, password) =>
  request.post(API.registered, { username, password }, { noNeedToken: true })

/**
 * 查看作品收藏列表
 * @param {String} phoneNumber 电话号码
 * @returns
 */
export const selCollectionWorksList = phoneNumber =>
  request.get(API.selCollectionWorksList, { params: { phoneNumber } })

/**
 *绑定手机号
 * @param {object} phoneBind 绑定电话模型
 * @returns
 */
export const phoneBind = phoneBindInfo => request.post(API.phoneBind, phoneBindInfo)

/**
 * 新增收货地址
 * @param {*} basicData 新增地址数据
 * @returns
 */
export const addAddress = basicData => request.post(API.addAddress, basicData)
/**
 * 修改收货地址
 * @param {*} basicData 修改地址数据
 * @returns
 */
export const updateAddress = basicData => request.put(API.updateAddress, basicData)
/**
 * 删除收货地址
 * @param {*} basicData 删除地址数据
 * @returns
 */
export const deleteAddress = basicData => request.post(API.deleteAddress, basicData)
/**
 * 查询客户地址
 * @param {*} customerId 客户ID
 * @returns
 */
export const selAddress = customerId => request.get(API.selAddress, { params: { customerId } })
